/*
* Copyright (c) 2009 contentismissing.net, artifacts.de
*
* All rights reserved.
*
* Authors: Jens Lembke <j@contentismissing.net>;
*          Michael Markowski <m.markowski@artifacts.de>;
*
* All non-exclusive rights granted to Deutsche Telekom AG Laboratories
*
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
package net.contentismissing.tlabs.cocktailparty.ui
{


	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.events.Event;

	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	import mx.core.Application;

	import net.contentismissing.tlabs.cocktailparty.model.Model;
	import net.contentismissing.tlabs.cocktailparty.Constants;
	
	import org.cove.ape.ApeVector;
	import org.cove.ape.CircleParticle;
	/**
	  TODO: Complete ASDoc class comment Test
	  @author
	 */
	public class Bubble extends MovieClip
	{
		public static const DIST_FACTOR : Number = 300;
		public static const referenceX : Number = 640;
		public static const referenceY : Number = 400;
	
		
		public var mc : MovieClip;
		public var id : int;
		public var workspace : Workspace;
		public var particle : CircleParticle;
		public var radius : Number;
	
	
		public function Bubble(id : int , workspace : Workspace)
		{
			init(id  , workspace);
		}

		public function init(id : int  , workspace : Workspace) : void
		{
			this.workspace = workspace;
			this.id = id;
			mc = new Bubble_MC();
			radius = 40;
			
			this.addEventListener(Constants.kEventOnTouchBubble , onTouch);
			this.addEventListener(Constants.kEventOnReleaseBubble , onRelease);
			this.addEventListener(Constants.kEventOnDragBubble , onDrag);
			
			particle = new CircleParticle(this.x , this.y , radius , false , 1 , 0.2 , 0.45);
			particle.setDisplay(mc , 0 , 0 , 0);
		}

		

		/**
		* TOUCH EVENTS:
		*/
		public function onTouch() : void
		{
		
		}

		public function onRelease() : void
		{
		}

		public function onDrag() : void
		{
		}

		public function getid () : int
		{
			return this.id;
		}

		public override function getBounds(targetCoordinateSpace : DisplayObject) : Rectangle
		{
			return mc.getBounds(targetCoordinateSpace);
		}

		public override function get x() : Number
		{
			if (particle == null) return 0;
			if (particle.position == null) return 0;
			return particle.position.x;
		}

		public override function get y() : Number
		{
			if (particle == null) return 0;
			if (particle.position == null) return 0;
			return particle.position.y;
		}

		public function getHotSpot() : Point
		{
			/** Gibt die globalen Koordianten des Bubbels zurück **/
			return new Point(this.x , this.y);
		}

		public override function set x(x : Number) : void
		{
			particle.position = new ApeVector(x , this.y);
		}

		public override function set y(y : Number) : void
		{
			particle.position = new ApeVector(this.x , y);
		}

		public override function set rotation(rotation : Number) : void
		{
			mc.rotation = rotation;
		}

		public override function get rotation() : Number
		{
			return mc.rotation;
		}

		public override function set scaleX(value : Number) : void
		{
			super.scaleX = value;
			mc.scaleX = value;
			particle.radius = radius * value;
		}

		public override function set scaleY(value : Number) : void
		{
			super.scaleY = value;
			particle.radius = radius * value;
			mc.scaleY = value;
		}
	}
}
